package com.budwk.app.util.poiUtils.nutzBeanUtils;

import cn.hutool.core.util.StrUtil;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

/**
 * @author ZY.Wang
 * @since 2023/8/9
 */
public class NutzIocUtils implements Setup {

    public static Ioc ioc;

    public void init(NutConfig conf) {
        NutzIocUtils.ioc = conf.getIoc();
    }

    @Override
    public void destroy(NutConfig nutConfig) {

    }

    public static Ioc getIoc() {
        return ioc;
    }

    public static Object getBeanByType(Class<?> clazz) {
        return ioc.getByType(clazz);
    }

    public static PropertiesProxy getPropertiesProxy() {
        return ioc.getByType(PropertiesProxy.class);
    }

    public static String getOssPrefix() {
        return getPropertiesProxy().get("huawei-oss.url");
    }
    public static String getOssPrefixHuaWei() {
        return getPropertiesProxy().get("huawei-oss.myhuaweicloud_url");
    }

    public static String getOssProxy() {
        String pre= getPropertiesProxy().get("huawei-oss.proxy_url");
        if(StrUtil.isNotEmpty(pre)){
            return pre;
        }
        return getPropertiesProxy().get("huawei-oss.url");

    }
    public static <T> T getBean(Class<T> clazz) {
        return ioc.getByType(clazz);
    }

    public static <T> T getPointBean(String beanName, Class<T> clazz) {
        return ioc.get(clazz,beanName);
    }


}
